package org.shj.jvm.oom;

import java.util.ArrayList;
import java.util.List;


/**
 * VM args: -Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError
 * 
 * -XX:+HeapDumpOnOutOfMemoryError Add this argument to dump the error log when there is OutOfMemory exception
 * 
 * @author huangjian
 *
 */
public class HeapOOM {

	public static void main(String[] args) throws Exception{
		System.out.println("Hello Heap outof memory");
		List<Person> list = new ArrayList<Person>();
		int cnt = 0;
		while(true){
			list.add(new Person());
			Thread.sleep(50);//这段代码是为了便于用jconsole观察内存使用状况
			System.out.println(++cnt);
		}
	}
}

class Person{
	private byte[] big = new byte[1024];
}
